//
//  htvmainform.m
//  MaiYaApp
//
//  Created by zhangwq on 15/10/20.
//  Copyright © 2015年 HT. All rights reserved.
//

#import "htvmainform.h"
#import "HTSysParam.h"
#import "HTFrameNet.h"
#import "HTFrameAlert.h"
#import "htvloadcity.h"
#import "UIImageView+WebCache.h"

static NSString *SectionsTableIdentifier=@"cellname";

@interface htvmainform (){
    NSMutableArray *hotActives;
    NSMutableArray *hotUsers;
    NSMutableArray *niceClubs;
    NSMutableArray *hotCicles;
    CGFloat width;
    CGFloat height;
    NSMutableArray *hotActivesArray;
    NSMutableArray *idArray;
    NSTimer *timer;
    NSString *localCity;
    UIWebView *webview;
    
    
}

@property ABCIntroView *introView;
@property (nonatomic, strong) NSOperationQueue *queue;

@end

@implementation htvmainform


- (NSOperationQueue *)queue {
    if (!_queue) _queue = [[NSOperationQueue alloc] init];
    return _queue;
}

- (void)viewDidLoad {
    
    [super viewDidLoad];
    [self initCity];
    [self toLoginAction];
    CGRect rect = [[UIScreen mainScreen] bounds];
    CGSize size = rect.size;
    width = size.width;
    height = size.height;
    
    
    
    localCity=@"";

    self.tableView.delegate=self;
    self.tableView.dataSource=self;
    
    self.tableView.separatorStyle=NO;
    
    self.navigationController.navigationBar.barTintColor = [UIColor colorWithRed:194.0/255 green:7.0/255 blue:30.0/255 alpha:1.0f];

    self.navigationController.navigationBar.tintColor=[UIColor whiteColor];
    [self.navigationController.navigationBar setTitleTextAttributes:
     
     @{NSFontAttributeName:[UIFont systemFontOfSize:14],
       
       NSForegroundColorAttributeName:[UIColor whiteColor]}];
    
    [self.cityBarItem
     setTitleTextAttributes:[NSDictionary
                             dictionaryWithObjectsAndKeys:[UIFont
                                                           boldSystemFontOfSize:14], NSFontAttributeName,nil] forState:UIControlStateNormal];
    
    
    
    hotActives=[NSMutableArray array];
    hotUsers=[NSMutableArray array];
    niceClubs=[NSMutableArray array];
    hotCicles=[NSMutableArray array];
    
    hotActivesArray=[NSMutableArray array];
    

    
    [self refreshListData];
    webview=[[UIWebView alloc]init];
    [self loading];
    
    
    
    

}

-(void)initCity{
    if([[HTSysParam cityCode] isEqualToString:@""]){
        NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
        [defaults setObject:@"01001" forKey:@"cityCode"];
        [defaults setObject:@"上海" forKey:@"cityName"];
        
        NSDictionary *dict=@{@"cityCode":@"01001",@"city":@"上海"};
        [HTSysParam loadChangeCity:dict];
    }
}

-(void)loading{
    
    webview=[[UIWebView alloc]initWithFrame:CGRectMake(-10, 0, width+10, height)];
    NSBundle *bundle = [NSBundle mainBundle];
    NSString *resPath = [bundle resourcePath];
    NSString *filePath = [resPath stringByAppendingPathComponent:@"demo8.html"];
    
    [webview loadHTMLString:[NSString stringWithContentsOfFile:filePath]
                    baseURL:[NSURL fileURLWithPath:[bundle bundlePath]]];
    [self.tableView addSubview:webview];
    
}
//刷新数据
-(void)refreshListData
{
    self.cityBarItem.title=[[NSString alloc]initWithFormat:@"%@ ▾",[HTSysParam city]];
    localCity=[HTSysParam city];
    hotActives=[NSMutableArray array];
    hotUsers=[NSMutableArray array];
    niceClubs=[NSMutableArray array];
    hotCicles=[NSMutableArray array];
    
    NSString *serverUrl=[[NSString alloc]initWithFormat:@"%@\/%@\/",[HTSysParam erpServer],[HTSysParam erpVirDir]];
    HTFrameNet *htnet=[[HTFrameNet alloc] initWithServerUrl:serverUrl];
    NSDictionary *dict = @{@"content":@{@"cityCode":[HTSysParam cityCode],
        @"mRequestMark":@0}};
    [htnet hmNetWCFmethodName:@"index" andDic:dict complete:^(NSString *backstr)
     {
         NSDictionary *rootDict=[HTFrameNet hmConvertDictFromJsonStr:backstr];
         NSDictionary *error=[rootDict objectForKey:@"error"];

         NSDictionary *body=[rootDict objectForKey:@"body"];
         if(body!=nil){
             hotActives=[body objectForKey:@"hotActives"];
             hotUsers=[body objectForKey:@"hotUsers"];
             niceClubs=[body objectForKey:@"niceClubs"];
             hotCicles=[body objectForKey:@"hotCicles"];
             
             [self sethotActivesArray];
             
             [self.tableView reloadData];
             
             timer =  [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(function:) userInfo:nil repeats:YES];
             
             
         }
  
         
     }];
    
     timer =  [NSTimer scheduledTimerWithTimeInterval:3.0 target:self selector:@selector(referTime:) userInfo:nil repeats:YES];
    
}


-(void)toLoginAction{
    if([[HTSysParam quitFlag] isEqualToString:@"1"]){
        [HTSysParam loadParamWithQuitFlag:@""];
        NSString *storyboard=@"MYLogin";
        NSString *Identifier=@"MYLogin";
        UIStoryboard *valueView = [UIStoryboard storyboardWithName:storyboard bundle:nil];
        UIViewController *uv=[valueView instantiateViewControllerWithIdentifier:Identifier];
        UINavigationController *baNavigation = [[UINavigationController alloc] initWithRootViewController:uv];
        [self presentModalViewController:baNavigation animated:YES];
        
        //返回
    }
}


-(void)viewDidAppear:(BOOL)animated
{
    if(!animated)
    {
        if([[HTSysParam userID]isEqualToString:@""]){
            [self initCity];
            [self refreshListData];
        }
    }

    
}



-(void)function:(id)sender{
    if(![localCity isEqualToString:[HTSysParam city]]){
        [self cityChanging];
    }
}


-(void)referTime:(id)sender{
    
    if([hotActives count]==0){
        [self refreshListData];
        NSLog(@"我是定时更新器！");
    }
}


//页面将要进入前台，开启定时器
-(void)viewWillAppear:(BOOL)animated
{
    //开启定时器
    [timer setFireDate:[NSDate distantPast]];
}

//页面消失，进入后台不显示该页面，关闭定时器
-(void)viewDidDisappear:(BOOL)animated
{
    //关闭定时器
    [timer setFireDate:[NSDate distantFuture]];
}







-(void)sethotActivesArray
{
    hotActivesArray=[NSMutableArray array];
    idArray=[NSMutableArray array];
    for (int i=0;i<[hotActives count];i++) {
        NSDictionary *dict=[hotActives objectAtIndex:i];
        [hotActivesArray insertObject:[dict objectForKey:@"pic"] atIndex:i];
        [idArray insertObject:[dict objectForKey:@"id"] atIndex:i];
    }
    
}





//返回行
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSDictionary * dict=[[NSDictionary alloc]init];
    
    UITableViewCell  *cell =(UITableViewCell *)[tableView dequeueReusableCellWithIdentifier:SectionsTableIdentifier];
    
    CGFloat rowWidth=(width-26)/4;
    
    if([indexPath section]==0){
        
        if([hotActivesArray count]>0){
            UIView *uv=[[UIView alloc]initWithFrame:CGRectMake(0, 0, width, 200)];
            
            self.introView = [[ABCIntroView alloc] initWithFrame:self.view.frame];
            self.introView.delegate = self;
            self.introView.clickFlag=1;
            self.introView.picArray=hotActivesArray;
            self.introView.idArray=idArray;
            [uv addSubview:self.introView];
            
            [cell addSubview:uv];
            
        }
        
        
    }
    else if([indexPath section]==1){
        
        UIView *uv1=[[UIView alloc]initWithFrame:CGRectMake(10, 0, rowWidth, 120)];
        UIImageView *iv1=[[UIImageView alloc]initWithFrame:CGRectMake(0, 0, rowWidth, 100)];
        if([hotCicles count]>0){
            NSDictionary *dict=[hotCicles objectAtIndex:0];
            iv1.accessibilityLabel=[dict objectForKey:@"imageUrl"];
            [iv1 setClipsToBounds:YES];
            [iv1 setContentMode:UIViewContentModeScaleAspectFill];
            [self downloadImg:iv1];
            [uv1 addSubview:iv1];
            
            UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(hotContentAction:)];
            tapGesture.accessibilityLabel=[dict objectForKey:@"id"];
            [uv1 addGestureRecognizer:tapGesture];
            
        }
        else{
            iv1.image=[UIImage imageNamed:@"null"];
            [uv1 addSubview:iv1];
        }
        [cell addSubview:uv1];
        
        UIView *uv2=[[UIView alloc]initWithFrame:CGRectMake(rowWidth+12, 0, rowWidth, 120)];
        UIImageView *iv2=[[UIImageView alloc]initWithFrame:CGRectMake(0, 0, rowWidth, 100)];
        if([hotCicles count]>1){
            NSDictionary *dict=[hotCicles objectAtIndex:1];
            iv2.accessibilityLabel=[dict objectForKey:@"imageUrl"];
            [iv2 setClipsToBounds:YES];
            [iv2 setContentMode:UIViewContentModeScaleAspectFill];
            [self downloadImg:iv2];
            [uv2 addSubview:iv2];
            
            UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(hotContentAction:)];
            tapGesture.accessibilityLabel=[dict objectForKey:@"id"];
            [uv2 addGestureRecognizer:tapGesture];
        }
        else{
            iv2.image=[UIImage imageNamed:@"null"];
            [uv2 addSubview:iv2];
        }
        [cell addSubview:uv2];
        
        
        UIView *uv3=[[UIView alloc]initWithFrame:CGRectMake(rowWidth*2+14, 0, rowWidth, 120)];
        UIImageView *iv3=[[UIImageView alloc]initWithFrame:CGRectMake(0, 0, rowWidth, 100)];
        if([hotCicles count]>2){
            NSDictionary *dict=[hotCicles objectAtIndex:2];
            iv3.accessibilityLabel=[dict objectForKey:@"imageUrl"];
            [iv3 setClipsToBounds:YES];
            [iv3 setContentMode:UIViewContentModeScaleAspectFill];
            [self downloadImg:iv3];
            [uv3 addSubview:iv3];
            
            UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(hotContentAction:)];
            tapGesture.accessibilityLabel=[dict objectForKey:@"id"];
            [uv3 addGestureRecognizer:tapGesture];
        }
        else{
            iv3.image=[UIImage imageNamed:@"null"];
            [uv3 addSubview:iv3];
        }
        [cell addSubview:uv3];
        
        UIView *uv4=[[UIView alloc]initWithFrame:CGRectMake(rowWidth*3+16, 0, rowWidth, 120)];
        UIImageView *iv4=[[UIImageView alloc]initWithFrame:CGRectMake(0, 0, rowWidth, 100)];
        if([hotCicles count]>3){
            NSDictionary *dict=[hotCicles objectAtIndex:3];
            iv4.accessibilityLabel=[dict objectForKey:@"imageUrl"];
            [iv4 setClipsToBounds:YES];
            [iv4 setContentMode:UIViewContentModeScaleAspectFill];
            [self downloadImg:iv4];
            [uv4 addSubview:iv4];
            
            UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(hotContentAction:)];
            tapGesture.accessibilityLabel=[dict objectForKey:@"id"];
            [uv4 addGestureRecognizer:tapGesture];
        }
        else{
            iv4.image=[UIImage imageNamed:@"null"];
            [uv4 addSubview:iv4];
        }
        [cell addSubview:uv4];
                
        
        
        
    }
    else if([indexPath section]==2){
        
        UIView *uv1=[[UIView alloc]initWithFrame:CGRectMake(10, 0, rowWidth, 100)];
        UIImageView *iv1=[[UIImageView alloc]initWithFrame:CGRectMake(0, 0, rowWidth, 80)];
        if([hotUsers count]>0){
            NSDictionary *dict=[hotUsers objectAtIndex:0];
            iv1.accessibilityLabel=[dict objectForKey:@"avatar"];
            [self downloadImg:iv1];
            [iv1 setClipsToBounds:YES];
            [iv1 setContentMode:UIViewContentModeScaleAspectFill];
            
            [uv1 addSubview:iv1];
            
            UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(hotUserAction:)];
            tapGesture.accessibilityLabel=[dict objectForKey:@"id"];
            [uv1 addGestureRecognizer:tapGesture];
        }
        else{
            iv1.image=[UIImage imageNamed:@"null"];
            [uv1 addSubview:iv1];
        }
        [cell addSubview:uv1];
        
        UIView *uv2=[[UIView alloc]initWithFrame:CGRectMake(rowWidth+12, 0, rowWidth, 100)];
        UIImageView *iv2=[[UIImageView alloc]initWithFrame:CGRectMake(0, 0, rowWidth, 80)];
        if([hotUsers count]>1){
            NSDictionary *dict=[hotUsers objectAtIndex:1];
            iv2.accessibilityLabel=[dict objectForKey:@"avatar"];
            [iv2 setClipsToBounds:YES];
            [iv2 setContentMode:UIViewContentModeScaleAspectFill];
            [self downloadImg:iv2];
            [uv2 addSubview:iv2];
            
            UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(hotUserAction:)];
            tapGesture.accessibilityLabel=[dict objectForKey:@"id"];
            [uv2 addGestureRecognizer:tapGesture];
        }
        else{
            iv2.image=[UIImage imageNamed:@"null"];
            [uv2 addSubview:iv2];
        }
        [cell addSubview:uv2];
        
        
        UIView *uv3=[[UIView alloc]initWithFrame:CGRectMake(rowWidth*2+14, 0, rowWidth, 100)];
        UIImageView *iv3=[[UIImageView alloc]initWithFrame:CGRectMake(0, 0, rowWidth, 80)];
        if([hotUsers count]>2){
            NSDictionary *dict=[hotUsers objectAtIndex:2];
            iv3.accessibilityLabel=[dict objectForKey:@"avatar"];
            [iv3 setClipsToBounds:YES];
            [iv3 setContentMode:UIViewContentModeScaleAspectFill];
            [self downloadImg:iv3];
            [uv3 addSubview:iv3];
            
            UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(hotUserAction:)];
            tapGesture.accessibilityLabel=[dict objectForKey:@"id"];
            [uv3 addGestureRecognizer:tapGesture];
        }
        else{
            iv3.image=[UIImage imageNamed:@"null"];
            [uv3 addSubview:iv3];
        }
        [cell addSubview:uv3];
        
        UIView *uv4=[[UIView alloc]initWithFrame:CGRectMake(rowWidth*3+16, 0, rowWidth, 100)];
        UIImageView *iv4=[[UIImageView alloc]initWithFrame:CGRectMake(0, 0, rowWidth, 80)];
        if([hotUsers count]>3){
            NSDictionary *dict=[hotUsers objectAtIndex:3];
            iv4.accessibilityLabel=[dict objectForKey:@"avatar"];
            [iv4 setClipsToBounds:YES];
            [iv4 setContentMode:UIViewContentModeScaleAspectFill];
            [self downloadImg:iv4];
            [uv4 addSubview:iv4];
            
            UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(hotUserAction:)];
            tapGesture.accessibilityLabel=[dict objectForKey:@"id"];
            [uv4 addGestureRecognizer:tapGesture];
        }
        else{
            iv4.image=[UIImage imageNamed:@"null"];
            [uv4 addSubview:iv4];
        }
        [cell addSubview:uv4];
        
        
    }
    else if([indexPath section]==3){
        
        UIView *uv1=[[UIView alloc]initWithFrame:CGRectMake(10, 0, rowWidth, 100)];
        UIImageView *iv1=[[UIImageView alloc]initWithFrame:CGRectMake(0, 0, rowWidth, 80)];
        
        if([niceClubs count]>0){
            NSDictionary *dict=[niceClubs objectAtIndex:0];
            iv1.accessibilityLabel=[dict objectForKey:@"pic"];
            [iv1 setClipsToBounds:YES];
            [iv1 setContentMode:UIViewContentModeScaleAspectFill];
            [self downloadImg:iv1];
            [uv1 addSubview:iv1];
            
            UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(hotClubAction:)];
            tapGesture.accessibilityLabel=[dict objectForKey:@"id"];
            [uv1 addGestureRecognizer:tapGesture];
        }
        else{
            iv1.image=[UIImage imageNamed:@"null"];
            [uv1 addSubview:iv1];
        }
        
        [cell addSubview:uv1];
        
        UIView *uv2=[[UIView alloc]initWithFrame:CGRectMake(rowWidth+12, 0, rowWidth, 100)];
        UIImageView *iv2=[[UIImageView alloc]initWithFrame:CGRectMake(0, 0, rowWidth, 80)];
        if([niceClubs count]>1){
            NSDictionary *dict=[niceClubs objectAtIndex:1];
            iv2.accessibilityLabel=[dict objectForKey:@"pic"];
            [iv2 setClipsToBounds:YES];
            [iv2 setContentMode:UIViewContentModeScaleAspectFill];
            [self downloadImg:iv2];
            [uv2 addSubview:iv2];
            
            UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(hotClubAction:)];
            tapGesture.accessibilityLabel=[dict objectForKey:@"id"];
            [uv2 addGestureRecognizer:tapGesture];
        }
        else{
            iv2.image=[UIImage imageNamed:@"null"];
            [uv2 addSubview:iv2];

        }
        [cell addSubview:uv2];
        
        
        UIView *uv3=[[UIView alloc]initWithFrame:CGRectMake(rowWidth*2+14, 0, rowWidth, 100)];
        UIImageView *iv3=[[UIImageView alloc]initWithFrame:CGRectMake(0, 0, rowWidth, 80)];
        if([niceClubs count]>2){
            NSDictionary *dict=[niceClubs objectAtIndex:2];
            iv3.accessibilityLabel=[dict objectForKey:@"pic"];
            [iv3 setClipsToBounds:YES];
            [iv3 setContentMode:UIViewContentModeScaleAspectFill];
            [self downloadImg:iv3];
            [uv3 addSubview:iv3];
            
            UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(hotClubAction:)];
            tapGesture.accessibilityLabel=[dict objectForKey:@"id"];
            [uv3 addGestureRecognizer:tapGesture];
        }
        else{
            iv3.image=[UIImage imageNamed:@"null"];
            [uv3 addSubview:iv3];
        }
        [cell addSubview:uv3];
        
        UIView *uv4=[[UIView alloc]initWithFrame:CGRectMake(rowWidth*3+16, 0, rowWidth, 100)];
        UIImageView *iv4=[[UIImageView alloc]initWithFrame:CGRectMake(0, 0, rowWidth, 80)];
        if([niceClubs count]>3){
            NSDictionary *dict=[niceClubs objectAtIndex:3];
            iv4.accessibilityLabel=[dict objectForKey:@"pic"];
            [iv4 setClipsToBounds:YES];
            [iv4 setContentMode:UIViewContentModeScaleAspectFill];
            [self downloadImg:iv4];
            [uv4 addSubview:iv4];
            
            UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(hotClubAction:)];
            tapGesture.accessibilityLabel=[dict objectForKey:@"id"];
            [uv4 addGestureRecognizer:tapGesture];
        }
        else{
            iv4.image=[UIImage imageNamed:@"null"];
            [uv4 addSubview:iv4];
        }
        [cell addSubview:uv4];

        
        
    }
    
    
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    
    
    [webview removeFromSuperview];
    
    return  cell;
}


//热门内容点击
-(void)hotContentAction:(UITapGestureRecognizer *)sender {
    UITapGestureRecognizer *sub=(UITapGestureRecognizer *)sender;
    NSString *storyboard=@"CircleDetail";
    NSString *Identifier=@"CircleDetail";
    UIStoryboard *valueView = [UIStoryboard storyboardWithName:storyboard bundle:nil];
    UIViewController *uv=[valueView instantiateViewControllerWithIdentifier:Identifier];
    UINavigationController *baNavigation = [[UINavigationController alloc] initWithRootViewController:uv];
    [uv setValue:sub.accessibilityLabel forKey:@"formdid"];//不需要强制转换也可以赋值
    [self presentModalViewController:baNavigation animated:YES];
    
    //返回
    
    [self dismissModalViewControllerAnimated:YES];
}


//热门用户
-(void)hotUserAction:(UITapGestureRecognizer *)sender {
    UITapGestureRecognizer *sub=(UITapGestureRecognizer *)sender;
    NSString *storyboard=@"UserPic";
    NSString *Identifier=@"UserPic";
    UIStoryboard *valueView = [UIStoryboard storyboardWithName:storyboard bundle:nil];
    UIViewController *uv=[valueView instantiateViewControllerWithIdentifier:Identifier];
    UINavigationController *baNavigation = [[UINavigationController alloc] initWithRootViewController:uv];
    [uv setValue:sub.accessibilityLabel forKey:@"formdid"];//不需要强制转换也可以赋值
    [uv setValue:@"1" forKey:@"pictype"];//不需要强制转换也可以赋值
    [self presentModalViewController:baNavigation animated:YES];
    
    //返回
    
    [self dismissModalViewControllerAnimated:YES];
}


//精品会所
-(void)hotClubAction:(UITapGestureRecognizer *)sender {
    UITapGestureRecognizer *sub=(UITapGestureRecognizer *)sender;
    NSString *storyboard=@"ClubDetail";
    NSString *Identifier=@"ClubDetail";
    UIStoryboard *valueView = [UIStoryboard storyboardWithName:storyboard bundle:nil];
    UIViewController *uv=[valueView instantiateViewControllerWithIdentifier:Identifier];
    UINavigationController *baNavigation = [[UINavigationController alloc] initWithRootViewController:uv];
    [uv setValue:sub.accessibilityLabel forKey:@"formdid"];//不需要强制转换也可以赋值
    [self presentModalViewController:baNavigation animated:YES];
    
    //返回
    
    [self dismissModalViewControllerAnimated:YES];
}


/**始终记住, 通过模型来修改显示. 而不要试图直接修改显示*/
- (void)downloadImg:(UIImageView *)theImageView {
    
    NSString *imageName=[[NSString alloc]initWithFormat:@"%@?imageView2/2/w/200",theImageView.accessibilityLabel];
    NSURL *imagePath = [NSURL URLWithString:imageName];
    [self.queue addOperationWithBlock: ^{

        //在主线程中更新UI
        [[NSOperationQueue mainQueue] addOperationWithBlock: ^{
            
            [theImageView sd_setImageWithURL:imagePath placeholderImage:[UIImage imageNamed:@"maiya"]];
            
            
            
        }];
    }];
}







#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    
    return 4;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    
    return 1;
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    if([indexPath section]==0){
        return 200;
    }
    else if([indexPath section]==1){
        return 100;
    }
    else{
        return 80;
    }
    
}

//设置Section头部区域高度
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    if(section==0){
        return 0;
    }
    else{
        return 40;
    }
}


- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{

    
    UIView * sectionView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, tableView.bounds.size.width, 80)];
    //[sectionView setBackgroundColor:[UIColor whiteColor]];
    if(section==1){
        UIImageView *iv=[[UIImageView alloc]initWithFrame:CGRectMake(10, 10, 20, 20)];
        iv.image=[UIImage imageNamed:@"maiya_7"];
        [sectionView addSubview:iv];
        
        UILabel *lb=[[UILabel alloc]initWithFrame:CGRectMake(35, 10, 80, 20)];
        lb.textColor=[UIColor blackColor];
        lb.font=[UIFont fontWithName:@"Baskerville" size:12.0];
        lb.text=@"热门内容";
        [sectionView addSubview:lb];
        
        UIButton *btn=[[UIButton alloc]initWithFrame:CGRectMake(width-50, 10, 50, 20)];
        [btn setTitle:@"更多 >" forState:UIControlStateNormal];
        btn.backgroundColor=[UIColor whiteColor];
        [btn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        [btn setFont: [UIFont systemFontOfSize: 12.0]];
        [btn addTarget:self action:@selector(moreCircleaction:) forControlEvents:UIControlEventTouchUpInside];

        [sectionView addSubview:btn];
    }
    if(section==2){
        UIImageView *iv=[[UIImageView alloc]initWithFrame:CGRectMake(10, 10, 20, 20)];
        iv.image=[UIImage imageNamed:@"maiya_10"];
        [sectionView addSubview:iv];
        
        UILabel *lb=[[UILabel alloc]initWithFrame:CGRectMake(35, 10, 80, 20)];
        lb.textColor=[UIColor blackColor];
        lb.font=[UIFont fontWithName:@"Baskerville" size:12.0];
        lb.text=@"热门用户";
        [sectionView addSubview:lb];
        
        UIButton *btn=[[UIButton alloc]initWithFrame:CGRectMake(width-50, 10, 50, 20)];
        [btn setTitle:@"更多 >" forState:UIControlStateNormal];
        btn.backgroundColor=[UIColor whiteColor];
        [btn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        [btn setFont: [UIFont systemFontOfSize: 12.0]];
        [btn addTarget:self action:@selector(moreUseraction:) forControlEvents:UIControlEventTouchUpInside];
        [sectionView addSubview:btn];
        
        
    }
    if(section==3){
        UIImageView *iv=[[UIImageView alloc]initWithFrame:CGRectMake(10, 10, 20, 20)];
        iv.image=[UIImage imageNamed:@"maiya_22"];
        [sectionView addSubview:iv];
        
        UILabel *lb=[[UILabel alloc]initWithFrame:CGRectMake(35, 10, 80, 20)];
        lb.textColor=[UIColor blackColor];
        lb.font=[UIFont fontWithName:@"Baskerville" size:12.0];
        lb.text=@"精品会所";
        [sectionView addSubview:lb];
        
        UIButton *btn=[[UIButton alloc]initWithFrame:CGRectMake(width-50, 10, 50, 20)];
        [btn setTitle:@"更多 >" forState:UIControlStateNormal];
        btn.backgroundColor=[UIColor whiteColor];
        [btn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        [btn setFont: [UIFont systemFontOfSize: 12.0]];
        [btn addTarget:self action:@selector(moreClubaction:) forControlEvents:UIControlEventTouchUpInside];
        [sectionView addSubview:btn];
    }
    return sectionView;
}


#pragma 更多

//热门用户
-(void)moreUseraction:(id)sender{
    NSString *storyboard=@"HotUser";
    NSString *Identifier=@"HotUser";
    UIStoryboard *valueView = [UIStoryboard storyboardWithName:storyboard bundle:nil];
    UITableViewController *uv=[valueView instantiateViewControllerWithIdentifier:Identifier];
    UINavigationController *baNavigation = [[UINavigationController alloc] initWithRootViewController:uv];
    [self presentModalViewController:baNavigation animated:YES];
    [self dismissModalViewControllerAnimated:YES];
}

//精品会所
-(void)moreClubaction:(id)sender{
    NSString *storyboard=@"HotClub";
    NSString *Identifier=@"HotClub";
    UIStoryboard *valueView = [UIStoryboard storyboardWithName:storyboard bundle:nil];
    UITableViewController *uv=[valueView instantiateViewControllerWithIdentifier:Identifier];
    UINavigationController *baNavigation = [[UINavigationController alloc] initWithRootViewController:uv];
    [self presentModalViewController:baNavigation animated:YES];
    [self dismissModalViewControllerAnimated:YES];
}

-(void)moreCircleaction:(id)sender{
    NSString *storyboard=@"HotCircle";
    NSString *Identifier=@"HotCircle";
    UIStoryboard *valueView = [UIStoryboard storyboardWithName:storyboard bundle:nil];
    UITableViewController *uv=[valueView instantiateViewControllerWithIdentifier:Identifier];
    UINavigationController *baNavigation = [[UINavigationController alloc] initWithRootViewController:uv];
    [self presentModalViewController:baNavigation animated:YES];
    [self dismissModalViewControllerAnimated:YES];
}




-(void)cityChanging{
    [self refreshListData];
}


- (IBAction)cityClickAction:(UIBarButtonItem *)sender {
    UITapGestureRecognizer *sub=(UITapGestureRecognizer *)sender;
    NSString *storyboard=@"LoadCity";
    NSString *Identifier=@"LoadCity";
    UIStoryboard *valueView = [UIStoryboard storyboardWithName:storyboard bundle:nil];
    htvloadcity *uv=[valueView instantiateViewControllerWithIdentifier:Identifier];
    uv.delegate=self;
    UINavigationController *baNavigation = [[UINavigationController alloc] initWithRootViewController:uv];
    
    [self presentModalViewController:baNavigation animated:YES];
    [self dismissModalViewControllerAnimated:YES];

}

-(void)onDoneButtonPressed:(NSString *)formid{
        NSString *storyboard=@"htvactiverec";
        NSString *Identifier=@"ActiveRec";
        UIStoryboard *valueView = [UIStoryboard storyboardWithName:storyboard bundle:nil];
        UIViewController *uv=[valueView instantiateViewControllerWithIdentifier:Identifier];
        UINavigationController *baNavigation = [[UINavigationController alloc] initWithRootViewController:uv];
        [uv setValue:formid forKey:@"formdid"];//不需要强制转换也可以赋值
        //[self.navigationController pushViewController: uv animated:false];
        [self presentModalViewController:baNavigation animated:YES];
    
        //返回
    
        [self dismissModalViewControllerAnimated:YES];
}

@end
